package com.claude.util;

import java.util.ArrayList;


import android.database.Cursor;

import com.claude.bean.Cron;
import com.claude.bean.Session;
import com.claude.bean.Student;
import com.claude.bean.Subject;
import com.claude.bean.User;

public class QueryParser {
	public static User getUser(Cursor cursor){
		if(cursor.moveToFirst()){
			User user = new User();
			user.setAccount(cursor.getString(cursor.getColumnIndex("aname")));
			user.setPassword(cursor.getString(cursor.getColumnIndex("apassword")));
			user.setTeacherNumber(cursor.getString(cursor.getColumnIndex("ano")));
			return user;
		}
		return null;
	}
	
	public static ArrayList<Subject> getSubjects(Cursor cursor){
		ArrayList<Subject> subjects = null;
		if(cursor.moveToFirst()){
			subjects = new ArrayList<Subject>();
			do{
				Subject tmpSubject = new Subject();
				tmpSubject.setName(cursor.getString(cursor.getColumnIndex("suname")));
				tmpSubject.setSubjectNumber(cursor.getString(cursor.getColumnIndex("suno")));
				subjects.add(tmpSubject);
			}while(cursor.moveToNext());
		}
		return subjects;
	}
	
	public static ArrayList<Session> getSessions(Cursor cursor){
		ArrayList<Session> sessions = null;
		if(cursor.moveToFirst()){
			sessions = new ArrayList<Session>();
			do{
				Session tmpSession = new Session();
				tmpSession.setClassName(cursor.getString(cursor.getColumnIndex("sename")));
				tmpSession.setSessionNumber(cursor.getString(cursor.getColumnIndex("seno")));
				sessions.add(tmpSession);
			}while(cursor.moveToNext());
		}
		return sessions;
	}
	
	public static Cron getCron(Cursor cursor){
		Cron cron = null;
		if(cursor.moveToFirst()){
			cron = new Cron();
			cron.setStartTime(cursor.getString(cursor.getColumnIndex("letime")));
			cron.setLessonNumber(cursor.getString(cursor.getColumnIndex("leno")));
		}
		return cron;
	}
	
	public static ArrayList<Student> getStudents(Cursor cursor){
		ArrayList<Student> students = null;
		if(cursor.moveToFirst()){
			students = new ArrayList<Student>();
			do{
				Student tmpStudent = new Student();
				tmpStudent.setCardMac(cursor.getString(cursor.getColumnIndex("stcard")));
				tmpStudent.setName(cursor.getString(cursor.getColumnIndex("stname")));
				tmpStudent.setSex(cursor.getString(cursor.getColumnIndex("sex")));
				tmpStudent.setStudentNumber(cursor.getString(cursor.getColumnIndex("stno")));
				students.add(tmpStudent);
			}while(cursor.moveToNext());
		}
		return students;
	}
}
 